import java.util.Stack;

public class WidthStack {
    class StockSpanner {
        private final Stack<Integer>priceStack;
        private final Stack<Integer>widthStack;
        public StockSpanner() {
            this.priceStack = new Stack<>();
            this.widthStack = new Stack<>();
        }

        public int next(int price) {
            int width = 1;
            while (!priceStack.isEmpty() && priceStack.peek() <= price){
                priceStack.pop();
                width += widthStack.pop();
            }
            priceStack.push(price);
            widthStack.push(width);
            return width;


        }
    }


}
